package cn.xiaoxiang.system.service.impl;

import cn.xiaoxiang.system.domain.Role;
import cn.xiaoxiang.system.mapper.MenuMapper;
import cn.xiaoxiang.system.mapper.PermissionMapper;
import cn.xiaoxiang.system.service.IRoleService;
import cn.xiaoxiang.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoxiang
 * @since 2022-11-29
 */
@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {
   @Autowired
    private MenuMapper menuMapper;
 @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public void add(Role role) {
        super.add(role);

        menuMapper.addMenuOrRole(role.getId(),role.getMenus());

        permissionMapper.addPerOrRole(role.getId(),role.getPermissions());

    }
    @Override
    public void update(Role role) {
        super.update(role);
        // 删除两个中间表
        menuMapper.deleteMiddle(role.getId());
        permissionMapper.deleteMiddle(role.getId());

        menuMapper.addMenuOrRole(role.getId(),role.getMenus());

        permissionMapper.addPerOrRole(role.getId(),role.getPermissions());
    }
}
